<div class="layui-fluid layui-anim febs-anim" id="businesses-major" lay-title="专业信息">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="major-table-form">
                        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
                            <legend style="font-size: 15px; font-weight: bolder;">批量查询</legend>
                        </fieldset>
                        <div class="layui-row">
                            <div class="layui-col-md10">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <label class="layui-form-label layui-form-label-sm">专业名称</label>
                                        <div class="layui-input-inline">
                                            <input type="text" name="fullName" minlength="2" maxlength="20" placeholder="全称、简称" autocomplete="off" class="layui-input">
                                        </div>
                                    </div>

                                </div>
                            </div>
                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="query">
                                    <!--查询图标-->
                                    <i class="layui-icon" title="查询">&#xe848;</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-green-plain table-action" id="reset">
                                    <!--刷新图标-->
                                    <i class="layui-icon" title="刷新">&#xe79b;</i>
                                </div>
                            </div>
                        </div>
                        <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">

                            <div class="layui-row">


                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="add">
                                    <i class="layui-icon layui-icon-plus-circle">新增</i>
                                </div>
                                <div class="layui-btn layui-btn-sm layui-btn-primary febs-button-blue-plain table-action" id="export">
                                    <i class="layui-icon layui-icon-export">导出</i>
                                </div>
                            </div>
                        </blockquote>
                    </form>
                    <table lay-filter="majorTable" lay-data="{id: 'majorTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="major-option">
<!--    详情图标-->
    <a lay-event="detail"><i
            class="layui-icon febs-edit-area febs-green" title="详情">&#xe7a5;</i></a>
<!--    修改图标-->
    <a lay-event="edit"><i
            class="layui-icon febs-edit-area febs-blue" title="编辑">&#xe7a4;</i></a>

</script>
<script data-th-inline="none" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'form', 'table', 'febs'], function () {
        let $ = layui.jquery,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            dropdown = layui.dropdown,
            $view = $('#businesses-major'),
            $query = $view.find('#query'),
            $add = $view.find('#add'),
            $export = $view.find('#export'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createTime', type: null},
            tableIns;

        form.render();

        initTable();



        table.on('tool(majorTable)', function (obj) {
            let data = obj.data,
                layEvent = obj.event;
            if (layEvent === 'detail') {
                febs.modal.view('专业信息', 'major/detail/' + data.id, {
                    area: $(window).width() <= 750 ? '95%' : '660px'
                });
            }
            if (layEvent === 'edit') {
                febs.modal.open('修改专业', 'major/update/' + data.id, {
                    area: $(window).width() <= 750 ? '90%' : '50%',
                    btn: ['提交', '取消'],
                    yes: function (index, layero) {
                        $('#major-update').find('#submit').trigger('click');
                        // 单击之后提交按钮不可选,防止重复提交
                        var DISABLED = 'layui-btn-disabled';
                        // 增加样式
                        $('#major-update').find('#submit').addClass(DISABLED);
                        // 增加属性
                        $('#major-update').find('#submit').attr('disabled', 'disabled');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
        });

        table.on('sort(majorTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        $query.on('click', function () {
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });

//        导出excel文件------
        $export.on('click',function () {
            let params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            params.pageSize = $view.find(".layui-laypage-limits option:selected").val();
            params.pageNum = $view.find(".layui-laypage-em").next().html();
            febs.download(ctx + 'major/excel', params, '院校专业.xlsx');
        })

        $add.on('click', function () {

            febs.modal.open('新增专业', 'major/add', {
                btn: ['提交', '重置'],
                area: $(window).width() <= 750 ? '95%' : '50%',
                yes: function (index, layero) {
                    $('#major-add').find('#submit').trigger('click');

                },
                btn2: function () {
                    $('#major-add').find('#reset').trigger('click');
                    return false;
                }
            });
        });


        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            tableIns.reload({where: getQueryParams(true), page: {curr: 1}, initSort: sortObject});
        });

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'majorTable',
                url: ctx + 'major/list',
                cols: [[
                    {type: 'checkbox'},
                    {field: 'fullName', title: '全称', minWidth: 100},
                    {field: 'simpleName', title: '简称', minWidth: 100},
                    {field: 'userName', title: '创建人'},
                    {field: 'createTime', title: '创建日期', minWidth: 165,sort: true},
                    {field: 'remark', title: '简介', minWidth: 180},
                    {title: '操作', toolbar: '#major-option', minWidth: 140}
                ]]
            });
        }

        function getQueryParams(flag) {
            let params = $searchForm.serializeJson();
            return params;
        }
    })
</script>